<?php

declare (strict_types=1);
namespace App\Model;

use Qbhy\HyperfAuth\Authenticatable;
use Hyperf\DbConnection\Model\Model;
/**
 * @property int $id 
 * @property string $account 
 * @property string $level 
 * @property string $balance 
 * @property int $star_currency 
 * @property int $points 
 * @property string $avatar 
 * @property string $nickname 
 * @property string $fullname 
 * @property string $password 
 * @property string $salt 
 * @property string $birthday 
 * @property string $city 
 * @property int $province_id 
 * @property int $city_id 
 * @property int $gender 
 * @property string $signature 
 * @property string $wechat 
 * @property string $qq 
 * @property string $phone 
 * @property string $steam 
 * @property string $official_server_id 
 * @property int $has_partner_privilege_official 
 * @property string $test_server_id 
 * @property int $has_partner_privilege_test 
 * @property string $last_login_at 
 * @property int $display_icon 
 * @property int $status 
 * @property int $deleted 
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 */
class User extends Model implements Authenticatable
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'user';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    //用户状态  0禁用 1启用
    public const ON_STATUS = 1;
    public const OFF_STATUS = 0;
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'star_currency' => 'integer', 'points' => 'integer', 'province_id' => 'integer', 'city_id' => 'integer', 'gender' => 'integer', 'has_partner_privilege_official' => 'integer', 'has_partner_privilege_test' => 'integer', 'display_icon' => 'integer', 'status' => 'integer', 'deleted' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];
    public function getId()
    {
        // 返回用户id
        return $this->id;
    }
    public static function retrieveById($key) : ?Authenticatable
    {
        // 通过id查找用户
        return self::query()->find($key);
    }
    /**
     * 生成密码加密扩展字符
     */
    public static function getSalt($length = 6)
    {
        // 密码字符集，可任意添加你需要的字符
        $str = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
        // 在 $str 中随机取 $length 个数组元素键名
        $keys = array_rand($str, $length);
        $res = '';
        for ($i = 0; $i < $length; $i++) {
            // 将 $length 个数组元素连接成字符串
            $res .= $str[$keys[$i]];
        }
        return $res;
    }
}